﻿using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using CthulhuDomain;
using CthulhuDomain.GameEntities;
using CthulhuDomain.StageManagement;
using Microsoft.Pex.Framework;
using Microsoft.Pex.Framework.Validation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Invaders.Test.Factories.GameEntities
{
  [TestClass]
  public partial class DomainFactoryFixture
  {
    private static ContentManager contentManager;

    [TestInitialize]
    public void TestInitialize() {
      var gd = new MockedGraphicsDeviceService(DeviceType.Hardware, GraphicsProfile.HiDef);
      gd.CreateDevice();

      string activeConfinguration;
#if DEBUG
      activeConfinguration = "Debug";
#else
      activeConfinguration = "Release";

#endif
      contentManager = new ContentManager(gd.ServiceProvider) {
        RootDirectory = Path.GetFullPath(string.Format("../../../CthulhuInvaders/bin/x86/{0}/Content/", activeConfinguration))
      };
    }

    [TestCleanup]
    public void MyTestCleanup() {
      contentManager = null;
    }


    [PexMethod,PexAllowedException(typeof(InvalidEnumArgumentException))]
    public DomainFactory DomainFactory_GetFactory_ShouldBeNotNull(DomainFactory.eTypeEntity typeEntity) {
      // Arrange
      // Act
      var factory = DomainFactory.GetFactory(typeEntity);

      // Assert
      Assert.IsNotNull(factory);
      Trace.WriteLine(string.Format("Type of instanced Domain factory is : {0};", factory.GetType()));

      return factory;
    }

    [PexMethod, PexAllowedException(typeof(InvalidEnumArgumentException))]
    public DomainEntity DomainFactory_CreateEntity_ShouldBeNotNull(DomainFactory.eTypeEntity typeEntity)
    {
      // Arrange
      var adapter = new ContentManagerAdapter(contentManager);
      var factory = DomainFactory_GetFactory_ShouldBeNotNull(typeEntity);
      // Act
      var entity = factory.CreateEntity(adapter);
        
      // Assert
      Assert.IsNotNull(entity);
      Trace.WriteLine(string.Format("Type of instanced Domain entity is : {0};", entity.GetType()));

      return entity;
    }
  }
}
